import {
	sqlHelper
} from './sqlHelper'
import {
	tempTable
} from './tempTable'
let tempShortData = {};
//短连接
tempShortData.GetListByParameter = () => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: 'http://s.lv-yan.com/Long/GetListByParameter',
			data: {
				TenantID: 9,
				murl: 'http://m.is.lv-yan.com/equipment'
			},
			success(e) {
				resolve(e)
			},
			fail(e) {
				resolve(e)
			}
		})
	})
}
/*
把所有的短连接放进 本地
http://s.lv-yan.com/Long/GetListByParameter?TenantID=15&murl=http://m.is.lv-yan.com/equipment
[{Id: 1,createdate: '2020-01-2',url: 'http://www.baidu.com',lvyan_key: '1'}
*/
tempShortData.AddShortData = (data) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.Short.TableName, tempTable.Short.Columns);
		}).then(e => {
			return sqlHelper.Insert(tempTable.Short.TableName, data)
		}).then(e => {
			resolve(e)
		})
	})
};
/*
查看所有的短连接
*/
tempShortData.GetAllShortData = () => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.Short.TableName, tempTable.Short.Columns);
		}).then(e => {
			return sqlHelper.FindAll(tempTable.Short.TableName)
		}).then(e => {
			resolve(e)
		})
	})
};
/*
通过短连接查看某个连接
*/
tempShortData.GetShortDataById = (Id) => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.Short.TableName, tempTable.Short.Columns);
		}).then(e => {
			return sqlHelper.FindAll(tempTable.Short.TableName)
		}).then(e => {
			let findOne = e.data.find(t => t.Id == Id)
			resolve(findOne)
		})
	})
};

/*删除所有的*/
tempShortData.DeleteAllShortData = () => {
	return new Promise((resolve, reject) => {
		sqlHelper.OpenDB().then(e => {
			return sqlHelper.CreateTable(tempTable.Short.TableName, tempTable.Short.Columns);
		}).then(e => {
			return sqlHelper.DeleteAll(tempTable.Short.TableName)
		}).then(e => {
			resolve(e)
		})
	})
};


module.exports = {
	tempShortData
}
